// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   BehaviorFactory.java

package jones.behavior;

import java.beans.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

// Referenced classes of package jones.behavior:
//            Behavior, BehaviorFactoryException

public class BehaviorFactory {

	public BehaviorFactory() {
	}

	public static Behavior copy(Behavior behavior)
			throws BehaviorFactoryException {
		try {
			Behavior copy;
			Class behaviorClass = ((Object) (behavior)).getClass();
			copy = (Behavior) behaviorClass.newInstance();
			BeanInfo behaviorInfo = Introspector.getBeanInfo(behaviorClass);
			PropertyDescriptor propertyDescriptors[] = behaviorInfo
					.getPropertyDescriptors();
			for (int i = 0; i < propertyDescriptors.length; i++) {
				Method readMethod = propertyDescriptors[i].getReadMethod();
				Method writeMethod = propertyDescriptors[i].getWriteMethod();
				if (readMethod != null && writeMethod != null) {
					Object args[] = { readMethod.invoke(((Object) (behavior)),
							new Object[0]) };
					writeMethod.invoke(((Object) (copy)), args);
				}
			}

			return copy;
		} catch (InstantiationException ex) {
			throw new BehaviorFactoryException("Instantiation failed");
		} catch (IllegalAccessException ex) {
			throw new BehaviorFactoryException("Illegal access.");
		} catch (IntrospectionException ex) {
			throw new BehaviorFactoryException("Introspection failed");
		} catch (IllegalArgumentException ex) {
			throw new BehaviorFactoryException("Illegal argument");
		} catch (InvocationTargetException ex) {
			throw new BehaviorFactoryException("Invocation failed");
		}
	}
}
